package com.yang.service.wximpl;

import com.yang.bean.MarketUser;
import com.yang.bean.MarketUserExample;
import com.yang.bean.common.BaseRespVo;
import com.yang.mapper.MarketUserMapper;
import com.yang.service.wx.WXAUthService;
import org.omg.CORBA.MARSHAL;
import org.springframework.beans.Mergeable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author: 杨庆
 * @since: 2022.9.11 13:28
 * @description:
 */
@Service
public class WXAUthServiceImpl implements WXAUthService {
    @Autowired
    MarketUserMapper marketUserMapper;
    @Override
    public BaseRespVo registerUser(MarketUser marketUser) {
        MarketUserExample example = new MarketUserExample();
        MarketUserExample.Criteria criteria = example.createCriteria();
        criteria.andMobileEqualTo(marketUser.getMobile());
        List<MarketUser> marketUsers = marketUserMapper.selectByExample(example);
        if (marketUsers.size()>0) {
            return BaseRespVo.invalidParameter("手机号已经注册！");
        }
        //TOD0

        //创建一个新的用户
        marketUser.setAddTime(new Date());
        marketUser.setNickname(marketUser.getUsername());
        marketUser.setAvatar("https://yanxuan.nosdn.127.net/80841d741d7fa3073e0ae27bf487339f.jpg?imageView&quality=90&thumbnail=64x64");
//        MarketUserExample example1 = new MarketUserExample();
        marketUserMapper.insertSelective(marketUser);

        return BaseRespVo.ok("注册用户完成");

    }

    @Override
    public BaseRespVo resetPassword(MarketUser marketUser) {
        //TODO 根据用户的手机号修改用户的密码
        MarketUserExample example = new MarketUserExample();
        MarketUserExample.Criteria criteria = example.createCriteria();
        criteria.andMobileEqualTo(marketUser.getMobile());
        int i = marketUserMapper.updateByExampleSelective(marketUser, example);
        if (i == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.error("修改密码失败！");
    }
}
